package com.jd.jdt.std.yfk.admin.service.workbenches.impl;

import com.jd.jdt.std.yfk.admin.service.workbenches.WorkbenchesService;
import com.jd.jdt.std.yfk.admin.service.workbenches.vo.FormInfoBean;
import com.jd.jdt.std.yfk.admin.service.workbenches.vo.UserProductInfoVo;
import com.jd.jdt.std.yfk.admin.service.workbenches.vo.WorkbenchesItemInfoVo;
import com.jd.jdt.std.yfk.admin.service.workbenches.vo.WorkbenchesItemVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

@Service
public class WorkbenchesServiceImpl implements WorkbenchesService {
    @Override
    public List<UserProductInfoVo> getUserProduct(FormInfoBean formInfoBean) {
        List<UserProductInfoVo> userProductInfoVoList = new ArrayList<>();
        if (formInfoBean.getUserCode().startsWith("1")){
            userProductInfoVoList.add(new UserProductInfoVo("25030","华住酒店","已开通","","",""));
        }else if (formInfoBean.getUserCode().startsWith("2")){
            userProductInfoVoList.add(new UserProductInfoVo("25030","华住酒店","已开通","","",""));
            userProductInfoVoList.add(new UserProductInfoVo("25248","荣耀","开通中","","",""));
        }else if (formInfoBean.getUserCode().startsWith("3")){
            userProductInfoVoList.add(new UserProductInfoVo("25030","华住酒店","已开通","","",""));
            userProductInfoVoList.add(new UserProductInfoVo("32001","供货贷","已开通","","",""));
            userProductInfoVoList.add(new UserProductInfoVo("25248","荣耀","开通中","","",""));
        }else{
            return null;
        }
        //指定了产品
        if (StringUtils.isNotBlank(formInfoBean.getProductCode())){
            Iterator<UserProductInfoVo> iterator = userProductInfoVoList.iterator();
            while (iterator.hasNext()) {
                if (!formInfoBean.getProductCode().equals(iterator.next().getProductCode())){
                    iterator.remove();
                }
            }
        }
        return userProductInfoVoList;
    }

    @Override
    public List<WorkbenchesItemVo> getUserProductInfo(UserProductInfoVo userProductInfoVo) {
        List<WorkbenchesItemVo> workbenchesItemVoList = new ArrayList<>();
        List<WorkbenchesItemInfoVo> item1 = new ArrayList<>();
        item1.add(new WorkbenchesItemInfoVo(String.format("产品名称：%s  产品编码：%s 产品状态：%s", "25030","华住酒店","正常")));
        List<WorkbenchesItemInfoVo> item2 = new ArrayList<>();
        item2.add(new WorkbenchesItemInfoVo("华住酒店: 华住酒店  :华住酒店 华住酒店  华住酒店\""));
        item2.add(new WorkbenchesItemInfoVo("华住酒店: 华住酒店  :华住酒店 华住酒店  华住酒店\""));
        item2.add(new WorkbenchesItemInfoVo("请求风控报文","{\"code\": \"0000\", \"data\": {\"code\": \"0000\", \"custNo\": \"C1002713625\", \"bizCode\": \"0000\", \"message\": \"成功\", \"bizSystem\": \"YSBP\", \"processNo\": \"CFDA00132420250516020303\", \"tfApplyNo\": \"C24041515312464362\", \"bizApplyNo\": \"A0025051601003008_1747332092661\", \"creditType\": \"1\", \"finishTime\": \"2025-02-11T15:31:25.000+08:00\", \"investorNo\": \"BANGHUI\", \"auditResult\": true, \"productCode\": \"27001\", \"channelApplyNo\": \"CFDA0013240415153124034ds92CCAA64\", \"creditApplyAmt\": 135000, \"investorProdCode\": \"INV1025\", \"approveCreditAmount\": 0}, \"message\": \"成功\"}","json"));
        List<WorkbenchesItemInfoVo> item3 = new ArrayList<>();
        item3.add(new WorkbenchesItemInfoVo("请求信贷报文","{\"data\": [{\"routeNo\": \"CreditRoute24051519240444574\", \"investorNo\": \"BANGHUI\", \"investorName\": \"上海邦汇商业保理有限公司\", \"investorProdCode\": \"INV1025\", \"investorUniqueCode\": \"\"}]}","json"));
        workbenchesItemVoList.add(new WorkbenchesItemVo("基本信息",item1));
        workbenchesItemVoList.add(new WorkbenchesItemVo("额度信息",item2));
        workbenchesItemVoList.add(new WorkbenchesItemVo("实名信息",item3));
        return workbenchesItemVoList;
    }

    @Override
    public String buildHtml(List<WorkbenchesItemVo> userProductInfo) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < userProductInfo.size(); i++) {
            WorkbenchesItemVo workbenchesItemVo = userProductInfo.get(i);
            sb.append("<div class=\"col-sm-12 search-collapse\">");
            sb.append("<h4>"+workbenchesItemVo.getItemName()+"</h4>");
            for (int j = 0; j < workbenchesItemVo.getWorkbenchesItemInfoVoList().size(); j++) {
                WorkbenchesItemInfoVo workbenchesItemInfoVo = workbenchesItemVo.getWorkbenchesItemInfoVoList().get(j);
                sb.append("<div class=\"form-group\">");
                    if ("json".equals(workbenchesItemInfoVo.getType())){
                        sb.append("\t<label class=\"col-sm-12 control-label\">"+workbenchesItemInfoVo.getName()+": <textarea  class=\"form-control\" rows=\"5\">"+workbenchesItemInfoVo.getValue()+"</textarea></label>");
                    }else{
                        sb.append("<label class=\"col-sm-12 control-label\">"+workbenchesItemInfoVo.getValue()+"</label>");
                    }
                sb.append("</div>");
            }
            sb.append("</div>");
        }
        return sb.toString();
    }
}
